import VwApp from './components/App.vue'

const nextDirection = (direction)=>{
  let el = document.querySelector('[vw-app]')

  if(el) el.setAttribute('transition-direction', direction)
}

export default {
  install(Vue, options){
    console.log('bbb')

    console.log(options)

    const router = options.router

    router.forward = (target)=>{
      nextDirection('forward')
    }

    router.back = (target)=>{
      nextDirection('back')
    }

    const appOptions = {
      router,
      components: {VwApp},

    }

    const app = new Vue(appOptions).$mount('vw-app')

    Vue.prototype.$app = window.$app = app
    window.$router = router


    return {app, router}
  },
  nextDirection: nextDirection,
  root(){
    return document.querySelector('[vw-app]')
  },
  pageContentScrollTop(scrollTop){
    const root = document.querySelector('[vw-app]')

    console.log(scrollTop)

    if(typeof scrollTop == 'number'){
      
      const pages = root && root.querySelectorAll('.vw-page .vw-page-content')
      const content = pages[pages.length -1]
      if(content){
        content.scrollTop = scrollTop
      }
    }else{
      
      return root && root.querySelector('.vw-page .vw-page-content')
        ? root.querySelector('.vw-page .vw-page-content').scrollTop
        : 0
    }
  }
}